package com.jielin.handling.controller.mobileapp;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.jielin.handling.Annotation.MyPower;
import com.jielin.handling.bean.AppResult;
import com.jielin.handling.entity.mobileapp.FeedBack;
import com.jielin.handling.entity.mobileapp.MessageNotification;
import com.jielin.handling.entity.mobileapp.MessageUser;
import com.jielin.handling.entity.tsuspect.TSuspec;
import com.jielin.handling.entity.vo.CaseVo;
import com.jielin.handling.entity.vo.TSuspecListVo;
import com.jielin.handling.entity.vo.mobileapp.MessageNotificationVo;
import com.jielin.handling.exception.ResultEnum;
import com.jielin.handling.service.mobileapp.FeedBackService;
import com.jielin.handling.service.mobileapp.MessageNotificationService;
import com.jielin.handling.service.record.RecordDetailedService;
import com.jielin.handling.service.room.RoomReserveLogService;

/**
 * @Title：MobilAppController.java
 * @Description：移动APP接口
 * @author WR
 * @date 2019年8月13日 上午8:49:36
 * @version 1.0
 */
@CrossOrigin
@RestController
@RequestMapping("/mobile/")
@MyPower(name = "移动APP接口", url = "/mobile")
public class MobileAppController {
	@Autowired
	FeedBackService feedBackService;
	@Autowired
	MessageNotificationService messageNotificationService;
	@Autowired
	private RecordDetailedService recordDetailedService;
	@Autowired
	private RoomReserveLogService roomReserveLogService;

	/**
	 * 添加意见反馈
	 * 
	 * @see com.jielin.handling.entity.mobileapp.FeedBack
	 * @param feedBack
	 * @return
	 */
	@MyPower(name = "添加意见反馈", url = "/addFeedBack", isPublic = true)
	@RequestMapping("addFeedBack")
	public AppResult addFeedBack(@RequestBody FeedBack feedBack) {
		AppResult result = new AppResult();
		JSONObject data = new JSONObject();
		int i = feedBackService.addFeedBack(feedBack);
		data.put("value", i);
		if (i > 0) {
			result.setCode(200);
			result.setMsg("添加成功！");
		} else {
			result.setCode(-1);
			result.setMsg("添加失败！");
		}
		result.setData(data);
		return result;
	}

	/**
	 * 查询消息提醒列表
	 * 
	 * @param unitCode   单位编号（非必传，可通过人员警号去查）
	 * @param policeCode 当前人员警号
	 * @param pageNum    从第几页开始
	 * @param pageSize   每页数量
	 * @return com.jielin.handling.entity.vo.mobileapp.MessageNotificationVo
	 */
	@MyPower(name = "查询消息提醒列表", url = "/findMessageNotification", isPublic = true)
	@RequestMapping("findMessageNotification")
	public AppResult findMessageNotification(@RequestBody JSONObject queryCondition) {
		AppResult result = new AppResult();
		JSONObject data = new JSONObject();
		MessageNotification mNotification = new MessageNotification();
		mNotification.setQueryCondition(queryCondition);
		data.put("value", messageNotificationService.findMessageNotification(mNotification));
		result.setCode(200);
		result.setMsg("查询消息提醒列表成功！");
		result.setData(data);
		return result;
	}

	/**
	 * 查询消息提醒详细信息
	 * 
	 * @param id         消息提醒id
	 * @param policeCode 警员编号
	 * @return
	 */
	@MyPower(name = "查询消息提醒详细信息", url = "/findMessageNotificationById", isPublic = true)
	@RequestMapping("findMessageNotificationById")
	public AppResult findMessageNotificationById(String id, String policeCode) {
		AppResult result = new AppResult();
		JSONObject data = new JSONObject();
		data.put("value", messageNotificationService.findMessageNotificationById(id, policeCode));
		result.setCode(200);
		result.setMsg("查询消息提醒详细信息！");
		result.setData(data);
		return result;
	}

	/**
	 * 设置消息提醒已读
	 * 
	 * @param msgNotificaId 消息提醒id逗号分隔
	 * @param policeCode    警员编号
	 * @return
	 */
	@MyPower(name = "设置消息提醒已读", url = "/updateMessageNotificationIsRead", isPublic = true)
	@RequestMapping("updateMessageNotificationIsRead")
	public AppResult updateMessageNotificationIsRead(@RequestBody MessageUser messageUser) {
		AppResult result = new AppResult();
		JSONObject data = new JSONObject();
		int i = messageNotificationService.updateMessageNotificationIsRead(messageUser);
		data.put("value", i);
		if (i > 0) {
			result.setCode(200);
			result.setMsg("全部已读成功！");
		} else {
			result.setCode(-1);
			result.setMsg("全部已读失败！");
		}
		result.setData(data);
		return result;
	}

	/**
	 * 根据嫌疑人id查询笔录信息
	 *
	 * @param suspectId 嫌疑人id
	 * @param number    第几次笔录
	 * @return
	 */
	@ResponseBody
	@MyPower(name = "根据嫌疑人id查询笔录信息", url = "/findDetailedBysuspectId")
	@RequestMapping(value = "/findDetailedBysuspectId")
	public AppResult findDetailedBySuspectId(String suspectId,
			@RequestParam(name = "number", required = false, defaultValue = "1") int number) {
		JSONObject data = new JSONObject();
		data.put("value", recordDetailedService.findDetailedBySuspectIdAndNum(suspectId, number));
		return AppResult.builder().setCode(ResultEnum.SUCCESS.getCode()).setMsg("查询笔录信息成功！").setData(data);
	}

	/**
	 * 根据policeId查询历史预约信息
	 *
	 * @param policeId 警员id
	 * @param pageNum  从第几页开始
	 * @param pageSize 每页数量
	 * @return
	 */
	@ResponseBody
	@MyPower(name = "根据嫌疑人id查询笔录信息", url = "/findReserveLogBypoliceId")
	@RequestMapping(value = "/findReserveLogBypoliceId")
	public AppResult findReserveLogBypoliceId(@RequestBody JSONObject queryCondition) {
		JSONObject data = new JSONObject();
		MessageNotification mNotification = new MessageNotification();
		mNotification.setQueryCondition(queryCondition);
		data.put("value", roomReserveLogService.findReserveLogBypoliceId(mNotification));
		return AppResult.builder().setCode(ResultEnum.SUCCESS.getCode()).setMsg("查询历史预约信息成功！").setData(data);
	}

	/**
	 * 根据时间查询案件详情信息
	 *
	 * @return
	 */

	@MyPower(name = "根据时间查询案件详情信息", url = "/selectCaseByTime", isPublic = true)
	@RequestMapping("selectCaseByTime")
	public AppResult selectCaseByTime(@RequestBody CaseVo vo) {
		AppResult result = new AppResult();
		JSONObject data = new JSONObject();
		List<CaseVo> vos = messageNotificationService.selectCaseByTime(vo);
		data.put("value", vos);
		result.setCode(200);
		result.setMsg("根据时间查询案件详情信息！");
		result.setData(data);
		return result;
	}

	/**
	 * 根据案件编号查询该案件下所有的嫌疑人
	 *
	 * @return
	 */
	@MyPower(name = "根据案件编号查询该案件下所有的嫌疑人", url = "/selectAllSusupect", isPublic = true)
	@RequestMapping("selectAllSusupect")
	public AppResult selectAllSusupect(String caseCode) {
		AppResult result = new AppResult();
		JSONObject data = new JSONObject();
		List<TSuspec> tSuspecs = messageNotificationService.selectAllSusupect(caseCode);
		data.put("value", tSuspecs);
		result.setCode(200);
		result.setMsg("根据案件编号查询该案件下所有的嫌疑人！");
		result.setData(data);
		return result;
	}

	/**
	 * 办理案件数
	 *
	 * @return
	 */
	@MyPower(name = "办理案件数", url = "/selectHandleCase", isPublic = true)
	@RequestMapping("selectHandleCase")
	public AppResult selectHandleCase(String unitcode, String type) {
		AppResult result = new AppResult();
		JSONObject data = new JSONObject();
		TSuspecListVo tSuspecs = messageNotificationService.selectHandleCase(unitcode, type);
		data.put("value", tSuspecs);
		result.setCode(200);
		result.setMsg("办理案件数！");
		result.setData(data);
		return result;
	}

	/**
	 * 添加Vpn服务器
	 *
	 * @return
	 */
	@MyPower(name = "添加Vpn服务器", url = "/addVpn", isPublic = true)
	@RequestMapping("addVpn")
	public AppResult addVpn(String vpnName, String userName, String passWord) {
		AppResult result = new AppResult();
		JSONObject data = new JSONObject();
//		int i = feedBackService.addVpn(feedBack);
//		data.put("value", i);
//		if (i > 0) {
//			result.setCode(200);
//			result.setMsg("添加Vpn服务器成功！");
//		} else {
//			result.setCode(-1);
//			result.setMsg("添加Vpn服务器失败！");
//		}
//		result.setData(data);
		return result;
	}
}
